import Vue from 'vue'
import {
	RouterMount,
	createRouter
} from 'uni-simple-router'
import {
	getToken
} from '@/utils/auth.js'
	
const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,  
	detectBeforeLock: (router, to, navType) => {
		router.$lockStatus=false;
	},
	routes: [
		...ROUTES
	]
});

router.beforeEach((to, from, next) => {
	let token = getToken();
	if(to.name === 'login' && token)
	{
		uni.switchTab({ url:'/pages/projectInfo/project-lists' })
	}
	else if(to.name !== 'login' && !token) 
	{
		uni.navigateTo({ url:'/pages/login/index' })
	}
	else{
		next();
	}
});

Vue.use(router);

export {
	router,
	RouterMount
}